﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Hotel.Models;
using Hotel.Models.Entity;
using Hotel.Models.Services;

namespace Hotel.Controllers
{
    public class AboutController : BaseController
    {
        //
        // GET: /About/

        public ActionResult About()
        {
            Cash cash = CashService.GetCash();
            ViewData["Cash"] = cash;
            HotelInformation HotelIf = HotelInformationService.GetHotelInformation();
            ViewData["HotelIf"] = HotelIf;
            List<GroupService> groupSrvc = GroupServiceService.GetListGroupService();
            ViewData["lstGroupSrvc"] = groupSrvc;
            double danhap = 0, tonkho = 0, daban = 0, tongcong = 0;
            List<GroupAndService> list = new List<GroupAndService>();
            foreach (GroupService groupService in groupSrvc)
            {
                GroupAndService gas = new GroupAndService();
                gas.GroupService = groupService;
                List<Service> srv = ServiceService.GetListServicebyGruopID(groupService.PkGroupService);
                foreach (Service service in srv)
                {
                    danhap += service.Entered;
                    tonkho += service.Instock;
                    daban += service.Outstock;
                    tongcong += service.Outstock * service.Price;
                }
                gas.LstServices = srv;
                list.Add(gas);
            }
            ViewData["groupAndService"] = list;
            ViewData["danhap"] = danhap;
            ViewData["tonkho"] = tonkho;
            ViewData["daban"] = daban;
            ViewData["tongcong"] = tongcong.ToString("#,##0");
            return View();
        }

        public ActionResult ChangeCurrentCulture(int culture)
        {
            //
            // Change the current culture for this user.
            //
            SiteSession.CurrentUICulture = culture;
            //
            // Cache the new current culture into the user HTTP session. 
            //
            Session["CurrentUICulture"] = culture;
            //
            // Redirect to the same page from where the request was made! 
            //
            return Redirect(Request.UrlReferrer.ToString());
        }

        [HttpPost]
        public bool EditCash(int id, int slctTimeCash, string slctCurencyCash, double convert, int slctRoundingCash, int slctOneCash,
                    int slctTwoCash, int slctThreeCash, int slctFreeCash)
        {
            Cash csh = new Cash(id, slctTimeCash, slctCurencyCash, convert, slctRoundingCash, slctOneCash, slctTwoCash, slctThreeCash, slctFreeCash);

            return CashService.SaveCash(csh);
        }

        [HttpPost]
        public bool EditHotel(string texthfullname, string texthshortname, int lstrank, string texthadd, string texthtel, string texthfax, string texthemail, string texthwebsite, string texthpolice, string texthcity, string hcontent)
        {
            HotelInformation csh = new HotelInformation(texthfullname, texthshortname, lstrank, texthadd, texthtel, texthfax, texthemail, texthwebsite, texthpolice, texthcity, hcontent);

            return HotelInformationService.SaveHotelInformation(csh);
        }

        [HttpPost]
        public bool AddService(int groupservice, string name, double price, string des, string donvi, bool isIn)
        {
            Service sv = new Service();
            sv.PkServiceId = 0;
            sv.GroupService.PkGroupService = groupservice;
            sv.Name = name;
            sv.Price = price;
            sv.Description = des;
            sv.Units = donvi;
            sv.IsInOut = isIn;
            return ServiceService.SaveService(sv, false);
        }


        [HttpPost]
        public bool EditService(int id, int groupservice, string name, double price, string des, string donvi, bool isIn)
        {
            Service sv = new Service();
            sv.PkServiceId = id;
            sv.GroupService.PkGroupService = groupservice;
            sv.Name = name;
            sv.Price = price;
            sv.Description = des;
            sv.Units = donvi;
            sv.IsInOut = isIn;
            return ServiceService.SaveService(sv, true);
        }

    }
}
